/*
 * ImageConverter.h
 *
 *  Created on: 24 mai 2012
 *      Author: turtlebot
 */

#ifndef IMAGECONVERTER_H_
#define IMAGECONVERTER_H_

#include <QtGui>
#include <QPaintEvent>
#include <QRect>


#include <ros/ros.h>
#include <image_transport/image_transport.h>
#include <cv_bridge/cv_bridge.h>
#include <sensor_msgs/image_encodings.h>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>

//#include <image_transport/subscriber.h>
#include <image_transport/image_transport.h>
#include <cv_bridge/CvBridge.h>
#include "KinectWidget.hpp"

namespace unicebot_gui {

class ImageConverter {
	//ros::NodeHandle nh_;
	//image_transport::ImageTransport it_;
	image_transport::Subscriber image_sub_;
	image_transport::Publisher image_pub_;
	std::string image_topic_in_;

	//boost::mutex image_mutex_;

	sensor_msgs::CvBridge img_bridge_;
	sensor_msgs::ImageConstPtr last_msg_;
	cv::Mat last_image_;

	KinectWidget* pKinectWin;
	QImage* pQtImg_;

public:
	ImageConverter();

	virtual ~ImageConverter();

	void init(ros::NodeHandle nh, std::string topic_in, KinectWidget* pKinectWin);

	void imageCb(const sensor_msgs::ImageConstPtr& msg);
	void imageCb2(const sensor_msgs::ImageConstPtr& msg);

	// Methodes de conversion
	//
	cv_bridge::CvImagePtr rosImageToCv(const sensor_msgs::ImageConstPtr& msg);
	QImage* cvImageToQt(const cv_bridge::CvImagePtr cv_ptr);
	void drawCvImage(const cv_bridge::CvImagePtr cv_ptr);
	QImage* Mat2QImage(const cv::Mat_<double> &src);
};

} //namespace unicebot_gui {
#endif /* IMAGECONVERTER_H_ */
